import configparser
from config.config import ENVIRONMENT_INI_PATH, MESSAGE_INI_PATH
from utils.decorator import singleton

@singleton
class GetConfig:

    def __init__(self):
        self.cfg = configparser.ConfigParser()

    def get_database_data(self, database):
        """
        获取mysql所有的节点和值
        :return:
        """
        # data = {}
        # for i in self.cfg.items("mysql"):
        #     data[i[0]] = i[1]

        self.cfg.read(ENVIRONMENT_INI_PATH, encoding="utf-8")

        data = dict(self.cfg.items(database))
        data["port"] = int(data["port"])
        return data

    def get_base_url(self, url):
        self.cfg.read(ENVIRONMENT_INI_PATH, encoding="utf-8")
        data = dict(self.cfg.items(url))
        return data.get("base_url")



    def get_message_dingding(self):
        self.cfg.read(MESSAGE_INI_PATH, encoding="utf-8")
        data = dict(self.cfg.items("dingding"))
        return data

    def get_message_wechat(self):
        self.cfg.read(MESSAGE_INI_PATH, encoding="utf-8")
        data = dict(self.cfg.items("wechat"))
        data["headers"] = eval(data["headers"])
        return data

    def get_message_email(self):
        self.cfg.read(MESSAGE_INI_PATH, encoding="utf-8")
        data = dict(self.cfg.items("email"))
        data["recipients"] = eval(data["recipients"])
        return data

    def get_message_report_path(self):
        self.cfg.read(MESSAGE_INI_PATH, encoding="utf-8")
        data = dict(self.cfg.items("report"))
        return data
